import { GetEcharts } from '@/utils/echarts'
import * as echarts from 'echarts';
export const GetdataZoomEchart = ( dom, list, colorlist,flag) => {
  let myChart = echarts.init(dom);
  const datazoom= [
    {type: 'inside',start: 0,end: 100},
    {start: 0,end: 100}
  ]
  const timePoints = list.find(ele => ele.datalist.length)?.datalist.map(item => item.timeReading)
  const series=list.map(ele => {
    return {
      name: ele.name,
      data: ele.datalist.map(ele => ele.valueReading),
      type: 'line',
      showSymbol: false,
      smooth: true
    }
  })
  let option = {
    toolbox: {
      feature: {
        dataZoom: {
          yAxisIndex: 'none'
        },
        restore: {},
        saveAsImage: {}
      }
    },
    grid: {
      top:'12%',
      left: "1%",
      right: "1%",
      bottom: flag?'24%':'5%',
      containLabel: true,
    },
    legend: {},
    color:colorlist,
    tooltip: {
      trigger: 'axis',
    },
    xAxis: {
      type: 'category',
      data: timePoints,
      axisPointer: {
        type: 'shadow'
      }
    },
    yAxis: {
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        },
        show: true
      },
      axisLine: {
        show: true,
      }
    },
    dataZoom:flag?datazoom:[],
    series
  };
  if (!flag) {
    delete option.toolbox.feature.dataZoom
    delete option.toolbox.feature.restore
  }
  option && myChart.setOption(option);
  window.addEventListener("resize", () => {
    myChart.resize();
  });
}